package cn.dgut.training.controller;

import cn.dgut.training.service.FileUploadService;
import cn.dgut.training.vo.CommonResponse;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/storage")
public class FileUploadController {


    @Autowired
    private FileUploadService fileUploadService;

    /**
     * 上传文件
     * @param file
     * @return
     */
    @PostMapping("/fileUpload")
    public CommonResponse fileUpload(@RequestParam("file") MultipartFile file){

        return CommonResponse.success(new Url(fileUploadService.upload(file)));

    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    class Url{
        String url;
    }
}
